package cn.seczone.iast.agent;

import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;

import java.util.List;

/**
 * 探针热部署
 *
 * @author XieShaoping
 */
public class AttachTest {

    public static void main(String[] args) throws Exception {
        List<VirtualMachineDescriptor> list = VirtualMachine.list();
        for (VirtualMachineDescriptor virtualMachineDescriptor : list) {
            // 程序以com.example.webdemo开头
            boolean b = virtualMachineDescriptor.displayName().startsWith("com.example.webdemo");
            if (b) {
                System.out.println(virtualMachineDescriptor.displayName() + "\t" + virtualMachineDescriptor.id());
                VirtualMachine vm = VirtualMachine.attach(virtualMachineDescriptor.id());
                vm.loadAgent("C:\\Users\\seczone\\Desktop\\RASP-engine\\engine\\agent\\target\\agent-1.0-all.jar");
                break;
            }
        }
    }

}
